package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	// 注册路由 router
	// func http.HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
	http.HandleFunc("/user", func(rw http.ResponseWriter, r *http.Request) {
		// r =======> 包含客户端发来的数据
		fmt.Println("用户请求详情：")
		fmt.Println("request: ", r)

		// rw =====> 通过rw将数据返回给客户端
		// 具体的业务处理逻辑
		io.WriteString(rw, "这是/user请求返回的数据")

	})

	http.HandleFunc("/name", func(rw http.ResponseWriter, r *http.Request) {
		io.WriteString(rw, "这是/name请求返回的数据")
	})

	http.HandleFunc("/id", func(rw http.ResponseWriter, r *http.Request) {
		io.WriteString(rw, "这是/id请求返回的数据")
	})

	fmt.Println("http server start 。。。")
	// func http.ListenAndServe(addr string, handler http.Handler) error
	if err := http.ListenAndServe("127.0.0.1:8088", nil); err != nil {
		fmt.Println("http start failded, err: ", err)
		return
	}

}
